//
//    AppConfig.swift
//
//    Create by 徐挺 陈 on 8/4/2018
//    Copyright © 2018. All rights reserved.
//    Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport

import Foundation
import SwiftyJSON
import PromiseKit



class AppConfig : NSObject, NSCoding{
    
    var aboutUrl : String!
    var agreementUrl : String!
    var appName : String!
    var contactusUrl : String!
    var downloadUrl : String!
    var helpUrl : String!
    var isUpdate : String!
    var totalLoan : String!
    var totalPeople : String!
    var version : String!
    
    
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!){
        if json.isEmpty{
            return
        }
        aboutUrl = json["aboutUrl"].stringValue
        agreementUrl = json["agreementUrl"].stringValue
        appName = json["appName"].stringValue
        contactusUrl = json["contactusUrl"].stringValue
        downloadUrl = json["downloadUrl"].stringValue
        helpUrl = json["helpUrl"].stringValue
        isUpdate = json["isUpdate"].stringValue
        totalLoan = json["totalLoan"].stringValue
        totalPeople = json["totalPeople"].stringValue
        version = json["version"].stringValue
    }
    
    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String:Any]
    {
        var dictionary = [String:Any]()
        if aboutUrl != nil{
            dictionary["aboutUrl"] = aboutUrl
        }
        if agreementUrl != nil{
            dictionary["agreementUrl"] = agreementUrl
        }
        if appName != nil{
            dictionary["appName"] = appName
        }
        if contactusUrl != nil{
            dictionary["contactusUrl"] = contactusUrl
        }
        if downloadUrl != nil{
            dictionary["downloadUrl"] = downloadUrl
        }
        if helpUrl != nil{
            dictionary["helpUrl"] = helpUrl
        }
        if isUpdate != nil{
            dictionary["isUpdate"] = isUpdate
        }
        if totalLoan != nil{
            dictionary["totalLoan"] = totalLoan
        }
        if totalPeople != nil{
            dictionary["totalPeople"] = totalPeople
        }
        if version != nil{
            dictionary["version"] = version
        }
        return dictionary
    }
    
    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        aboutUrl = aDecoder.decodeObject(forKey: "aboutUrl") as? String
        agreementUrl = aDecoder.decodeObject(forKey: "agreementUrl") as? String
        appName = aDecoder.decodeObject(forKey: "appName") as? String
        contactusUrl = aDecoder.decodeObject(forKey: "contactusUrl") as? String
        downloadUrl = aDecoder.decodeObject(forKey: "downloadUrl") as? String
        helpUrl = aDecoder.decodeObject(forKey: "helpUrl") as? String
        isUpdate = aDecoder.decodeObject(forKey: "isUpdate") as? String
        totalLoan = aDecoder.decodeObject(forKey: "totalLoan") as? String
        totalPeople = aDecoder.decodeObject(forKey: "totalPeople") as? String
        version = aDecoder.decodeObject(forKey: "version") as? String
        
    }
    
    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if aboutUrl != nil{
            aCoder.encode(aboutUrl, forKey: "aboutUrl")
        }
        if agreementUrl != nil{
            aCoder.encode(agreementUrl, forKey: "agreementUrl")
        }
        if appName != nil{
            aCoder.encode(appName, forKey: "appName")
        }
        if contactusUrl != nil{
            aCoder.encode(contactusUrl, forKey: "contactusUrl")
        }
        if downloadUrl != nil{
            aCoder.encode(downloadUrl, forKey: "downloadUrl")
        }
        if helpUrl != nil{
            aCoder.encode(helpUrl, forKey: "helpUrl")
        }
        if isUpdate != nil{
            aCoder.encode(isUpdate, forKey: "isUpdate")
        }
        if totalLoan != nil{
            aCoder.encode(totalLoan, forKey: "totalLoan")
        }
        if totalPeople != nil{
            aCoder.encode(totalPeople, forKey: "totalPeople")
        }
        if version != nil{
            aCoder.encode(version, forKey: "version")
        }
        
    }
    
    class func getAppConfig() -> Promise<AppConfig> {
        var appConfig : AppConfig!
        let dataFn = { (json: JSON) -> Void in
            appConfig = AppConfig(fromJson: json)
        }
        let request = RequestData(path: "Main/GetInitAppConfig")
        return netRequest(request, dataFn: dataFn).then { _ in
            return Promise(value: appConfig)
        }        
    }
    
}
